package cur.nature.domain.dao;

import cur.nature.domain.common.config.DBDomainConfig;
import cur.nature.domain.model.po.Domain_DictPO;
import cur.nature.domain.model.vo.Domain_DictVO;
import cur.nature.framework.mvc.crud.CrudDao;
import cur.nature.tinyorm.core.bean.PageBean;

import cur.nature.tinyorm.core.template.DefaultJdbcTemplate;
import cur.nature.framework.core.util.StringUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

/**
 * 通用字典表 Dao
 * 作者：Auto Generator By wujian
 * 生成日期：2023-07-09 16:05:31
 */
@Component
@DependsOn(DefaultJdbcTemplate.TEMPLATE)
@ConditionalOnProperty( value = {"cur.component.domain.enable"})
public class Domain_DictDao extends CrudDao<Domain_DictPO, Domain_DictVO> {
    public Domain_DictDao(@Qualifier(DBDomainConfig.TEMPLATE) DefaultJdbcTemplate template) {
        super( Domain_DictPO.class, Domain_DictVO.class, template);
    }

    public PageBean<Domain_DictVO> list(Domain_DictVO.list_Param param) throws Exception {
        StringBuilder condition = new StringBuilder(" 1=1 ");
        if(StringUtil.isNotEmpty(param.getKeyword())){
            condition.append(" and a.code like '"+param.getKeyword()+"%' ");
        }
        String sql = "select " + this.cols() + " from " + tableName() + " a " + " where " + condition;
        PageBean<Domain_DictVO> list = queryForPage(sql, param.buildPage(),
                null, Domain_DictVO.class);
        return list;
    }

}

